#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPixmap>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    manager = new QNetworkAccessManager(this);
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(func(QNetworkReply*)));
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    QString urlstr = ui->lineEdit->text();

    QUrl url(urlstr);

    QNetworkRequest request(url);

    manager->get(request);
}

void MainWindow::func(QNetworkReply *reply)
{
    QByteArray buf = reply->readAll();

    QPixmap map;
    map.loadFromData(buf);
    map.scaled(ui->label->width(),ui->label->height());
    //        让你的配置生效
    ui->label->setScaledContents(true);
    ui->label->setPixmap(map);
}
